#!/bin/bash

APP=education

if [ -n "$2" ] ;then
   do_date=$2
else 
   echo "请传入日期参数"
   exit
fi 
dws_user_user_login_td="
insert overwrite table ${APP}.dws_user_user_login_td partition (dt ='$do_date')
select u.id,
       nvl(login_date_last, date_format(create_time, 'yyyy-MM-dd')),
       nvl(login_count_td, 1)
from (
         select id,
                create_time
         from ${APP}.dim_user_zip
         where dt = '9999-12-31'
     ) u
         left join
     (
         select user_id,
                max(dt)  login_date_last,
                count(*) login_count_td
         from ${APP}.dwd_user_login_inc
         where dt = '$do_date'
         group by user_id
     ) l
     on u.id = l.user_id;
"
case $1 in
"dws_user_user_login_td")
    hive -e "$dws_user_user_login_td"
;;
"all")
    hive -e "$dws_user_user_login_td"
;;
esac